﻿using DFGK.IService;
using DFGK.Service;
using DFGK_WMS.Common;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Xml.Linq;

namespace DFGK_WMS.WebAPI.Controllers.PC.库存管理
{
    /// <summary>
    /// 库存预警
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "PC")]
    public class InventoryWarnController : BaseController
    {
        private readonly IInventoryService inventoryService;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="environment"></param>
        /// <param name="inventoryService"></param>
        public InventoryWarnController(IWebHostEnvironment environment, IInventoryService inventoryService) : base(environment)
        {
            this.inventoryService = inventoryService;
        }

        /// <summary>
        /// 库存预警
        /// </summary>
        /// <param name="type"></param>
        /// <param name="wid"></param>
        /// <param name="aid"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetInventoryWarnList(int? type, long? wid, long aid, int pageIndex, int pageSize)
        {
            if (pageIndex <= 0 || pageSize <= 0)
            {
                return Ok(BaseResult.Result("400", "分页条件有误！"));
            }
            int totalCount;

            var list = inventoryService.GetInventoryWarnList(type, wid, aid, pageIndex,pageSize, out totalCount);

            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", totalCount));
            }
            return Ok(BaseResult.Result(null, "查询失败！", "500", 0));
        }

        /// <summary>
        /// 修改状态为补货
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult UpdInventoryStatus(long id)
        {
            if(id<=0)
                return Ok(BaseResult.Result("400", "Id不能为空！"));

            string message;
            bool IsOK = inventoryService.UpdInventoryStatus(id, out message);
            if (IsOK)
            {
                return Ok(BaseResult.Result(true, "操作成功！", "200"));
            }
            return Ok(BaseResult.Result(false, "操作失败！" + message, "500"));
        }
    }
}
